adbox.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use client";
  2. import { AdItem } from "@/api/customservice";
  3. import { useRouter } from "@/i18n/routing";
  4. import React from "react";
  5. import { Pagination } from "swiper/modules";
  6. import { Swiper, SwiperSlide } from "swiper/react";
  7. interface AdboxProps {
  8. data: AdItem[];
  9. }
  10. const Adbox: React.FC<AdboxProps> = ({ data }) => {
  11. const router = useRouter();
  12. const doClick = async (data: AdItem) => {
  13. switch (data.action_type) {
  14. case 2:
  15. window.open(data.action_params, "_blank");
  16. break;
  17. case 3:
  18. let path = data.action_params;
  19. if (path) router.push(path);
  20. break;
  21. case 5:
  22. data?.action_params ? await eval(data?.action_params || "") : "";
  23. break;
  24. default:
  25. break;
  26. }
  27. };
  28. return (
  29. <div className="p-[.1rem]">
  30. <Swiper
  31. spaceBetween={10}
  32. autoplay
  33. modules={[Pagination]}
  34. pagination={{ clickable: true }}
  35. >
  36. {!!data?.length &&
  37. data.map((item) => {
  38. return (
  39. <SwiperSlide key={item.id} onClick={() => doClick(item)}>
  40. <img src={item.content} alt="" />
  41. </SwiperSlide>
  42. );
  43. })}
  44. </Swiper>
  45. </div>
  46. );
  47. };
  48. export default Adbox;